DEFINITION MODULE QuickDraw; (* Franz Kronseder 08.06.85 *)
                             (* last modified 08.06.85 *)
FROM SYSTEM IMPORT ADDRESS;			     
IMPORT MacBase;			     
EXPORT QUALIFIED
  systemFont,applFont,NewYork,Geneva,Monaco, (* Font Numbers *)
  Venice,London,Athens,SanFran,Toronto,
  srcCopy,srcOr,srcXor,srcBic,               (* BitMap transfer modes *)
  notSrcCopy,notSrcOr,notSrcXor,notSrcBic,
  patCopy,patOr, patXor,patBic,
  notPatCopy,notPatOr,notPatXor,notPatBic,
  Byte,StrPtr,LongInt,OsType,Point,          (* MacBase types *)
  Ptr,Handle,
  QDPtr,QDHandle,Str255,Pattern,PatPtr,PatHandle, (* QuickDraw Types *)
  Bits16,GrafVerb,StyleItem,Style,
  FontInfo,Rect,BitMap,CursHandle,Cursor,PenState,RgnHandle,Region,
  QDProcsPtr,QDProcs,GrafPtr,GrafPort,
  QDGPointer,QDG,QDGlobals,
  
  InitGraf,OpenPort,InitPort,ClosePort,SetPort,GetPort,GrafDevice,SetPortBits,PortSize,
  MovePortTo,SetOrigin,SetClip,GetClip,ClipRect,BackPat,InitCursor,SetCursor,HideCursor,
  ShowCursor,ObscureCursor,GetCursor,ShieldCursor,HidePen,ShowPen,GetPen,GetPenState,
  SetPenState,PenSize,PenMode,PenPat,PenNormal,MoveTo,Move,LineTo,Line,TextFont,
  TextFace,TextMode,TextSize,SpaceExtra,DrawChar,DrawString,DrawText,CharWidth,StringWidth,
  TextWidth,AddPt,SubPt,SetPt,EqualPt,ScalePt,MapPt,LocalToGlobal,GlobalToLocal,SetRect,
  EqualRect,EmptyRect,OffsetRect,MapRect,InsetRect,SectRect,UnionRect,PtInRect,Pt2Rect,
  FrameRect,PaintRect,EraseRect,InvertRect,FillRect,ScrollRect,CopyBits,GetIcon,PlotIcon,
  GetPattern,GetFontInfo,NewRgn,DisposeRgn,CopyRgn,SetEmptyRgn,SetRectRgn,FrameRgn,
  PaintRgn,EraseRgn,InvertRgn,FillRgn,TextBox;
  
CONST
  (* Font Numbers *)
  systemFont= 0;  applFont  = 1;  NewYork   = 2;  Geneva    = 3;
  Monaco    = 4;  Venice    = 5;  London    = 6;  Athens    = 7;
  SanFran   = 8;  Toronto   = 9;
  (* the 16 transfer modes *)
  srcCopy    = 0;  srcOr      = 1;  srcXor     = 2;  srcBic     = 3;
  notSrcCopy = 4;  notSrcOr   = 5;  notSrcXor  = 6;  notSrcBic  = 7;
  patCopy    = 8;  patOr      = 9;  patXor     =10;  patBic     =11;
  notPatCopy =12;  notPatOr   =13;  notPatXor  =14;  notPatBic  =15;
  
TYPE Byte   =MacBase.Byte;    (* = CHAR    *)
     StrPtr =MacBase.StrPtr;  (* = ADDRESS *)
     LongInt=MacBase.LongInt; (* = ADDRESS *)
     OsType =MacBase.OsType;  (* ARRAY[0..3] OF CHAR    *)
     Point  =MacBase.Point;   (* RECORD v,h:INTEGER END *)
     Handle =MacBase.Handle;
     
TYPE QDPtr     =  ADDRESS; 
     QDHandle  =  POINTER TO QDPtr;     
     Ptr       =  ADDRESS;
     Str255    =  ARRAY[0..255] OF CHAR;
     Pattern   =  ARRAY[0..7] OF CHAR;   (* 0..255 *)
     PatPtr    =  POINTER TO Pattern;
     PatHandle =  POINTER TO PatPtr;
     Bits16    =  ARRAY[0..15] OF CARDINAL;
                  (* VHSelect  =  (v,h); *)
     GrafVerb  =  (frame,paint,erase,invert,fill);
     StyleItem =  (bold,italic,underline,outline,shadow,condense,extend);
     Style     =  SET OF StyleItem;
     
 FontInfo  =  RECORD ascent,descent,widMax,leading: INTEGER;  END;

 Rect = RECORD CASE INTEGER
         OF 0: top,left,bottom,right :INTEGER;
          | 1: topLeft,botRight      : Point;
        END END;

 BitMap = 
  RECORD  baseAddr: QDPtr; rowBytes: INTEGER; bounds:Rect;  END;

 CursHandle = POINTER TO CursPtr; CursPtr = POINTER TO Cursor;
 Cursor     = RECORD data,mask: Bits16; hotSpot: Point; END;

 PenState =
  RECORD pnLoc,pnSize:Point; mode:INTEGER; pnPat:Pattern; END;

 RgnHandle = POINTER TO RgnPtr; RgnPtr = POINTER TO Region;
 Region    =  RECORD rgnSize: INTEGER; rgnBBox: Rect;  END;
             (* rgnSize = 10 for rectangular      *)
	     (* plus more data if not rectangular *)

QDProcsPtr = POINTER TO QDProcs;
QDProcs   = 
 RECORD textProc,lineProc,rectProc,rRectProc,ovalProc,
        arcProc,polyProc,rgnProc,bitsProc,commentProc,
	txMeasProc,getPicProc,putPicProc               :QDPtr; END;

 GrafPtr  = POINTER TO GrafPort;
 GrafPort =
  RECORD
   device:                   INTEGER;
   portBits:                 BitMap;
   portRect:                 Rect;
   visRgn,clipRgn:           RgnHandle;
   bkPat,fillPat:            Pattern;
   pnLoc,pnSize:             Point;
   pnMode:                   INTEGER;
   pnPat:                    Pattern;
   pnVis,txFont:             INTEGER;
   txFace:                   Style;
   txMode,txSize:            INTEGER;
   spExtra,fgColor,bkColor:  LongInt;
   colrBit,patStretch:       INTEGER;
   picSave,rgnSave,polySave: QDHandle;
   grafProcs:                QDProcsPtr;
  END;

QDGPointer = POINTER TO QDG; (* QuickDraw global variables *)
QDG =  RECORD randSeed  : LongInt;
              screenBits: BitMap;
              arrow     : Cursor;
              dkGray,ltGray,gray,black,white: Pattern;
              thePort   : GrafPtr
       END;
VAR QDGlobals:QDGPointer;(* variables defined in the rootloader*)
(*---------------------------------------------------------------------------*)
(* GrafPort Routines *)
PROCEDURE InitGraf   (globalPtr: QDPtr);
PROCEDURE OpenPort   (port: GrafPtr);                   (*INLINE $A86F*)
PROCEDURE InitPort   (port: GrafPtr);                   (*INLINE $A86D*)
PROCEDURE ClosePort  (port: GrafPtr);                   (*INLINE $A87D*)
PROCEDURE SetPort    (port: GrafPtr);                   (*INLINE $A873*)
PROCEDURE GetPort    (VAR port: GrafPtr);               (*INLINE $A874*)
PROCEDURE GrafDevice (device: INTEGER);                 (*INLINE $A872*)
PROCEDURE SetPortBits(VAR bm: BitMap);                  (*INLINE $A875*)
PROCEDURE PortSize   (width,height: INTEGER);           (*INLINE $A876*)
PROCEDURE MovePortTo (leftGlobal,topGlobal: INTEGER);   (*INLINE $A877*)
PROCEDURE SetOrigin  (h,v: INTEGER);                    (*INLINE $A878*)
PROCEDURE SetClip    (rgn: RgnHandle);                  (*INLINE $A879*)
PROCEDURE GetClip    (rgn: RgnHandle);                  (*INLINE $A87A*)
PROCEDURE ClipRect   (VAR r: Rect);                     (*INLINE $A87B*)
PROCEDURE BackPat    (VAR pat: Pattern);                (*INLINE $A87C*)

(* Cursor Routines *)
PROCEDURE InitCursor;                                   (*INLINE $A850*)
PROCEDURE SetCursor(VAR crsr: Cursor);                  (*INLINE $A851*)
PROCEDURE HideCursor;                                   (*INLINE $A852*)
PROCEDURE ShowCursor;                                   (*INLINE $A853*)
PROCEDURE ObscureCursor;                                (*INLINE $A856*)
PROCEDURE GetCursor (cursorID: INTEGER):  CursHandle;   (*INLINE $A9B9*)
PROCEDURE ShieldCursor(left,top,right,bottom: INTEGER); (*INLINE $A855*)

(* Line Routines *)
PROCEDURE HidePen;                                      (*INLINE $A896*)
PROCEDURE ShowPen;                                      (*INLINE $A897*)
PROCEDURE GetPen     (VAR pt: Point);                   (*INLINE $A89A*)
PROCEDURE GetPenState(VAR pnState: PenState);           (*INLINE $A898*)
PROCEDURE SetPenState(VAR pnState: PenState);           (*INLINE $A899*)
PROCEDURE PenSize    (width,height: INTEGER);           (*INLINE $A89B*)
PROCEDURE PenMode    (mode: INTEGER);                   (*INLINE $A89C*)
PROCEDURE PenPat     (VAR pat: Pattern);                (*INLINE $A89D*)
PROCEDURE PenNormal;                                    (*INLINE $A89E*)
PROCEDURE MoveTo     (h,v: INTEGER);                    (*INLINE $A893*)
PROCEDURE Move       (dh,dv: INTEGER);                  (*INLINE $A894*)
PROCEDURE LineTo     (h,v: INTEGER);                    (*INLINE $A891*)
PROCEDURE Line       (dh,dv: INTEGER);                  (*INLINE $A892*)


(* Text Routines *)
PROCEDURE TextFont     (font: INTEGER);                 (*INLINE $A887*)
PROCEDURE TextFace     (face: Style);                   (*INLINE $A888*)
PROCEDURE TextMode     (mode: INTEGER);                 (*INLINE $A889*)
PROCEDURE TextSize     (size: INTEGER);                 (*INLINE $A88A*)
PROCEDURE SpaceExtra   (extra: LongInt);                (*INLINE $A88E*)
PROCEDURE DrawChar     (ch: CHAR);                      (*INLINE $A883*)
PROCEDURE DrawString   (s:StrPtr);                      (*INLINE $A884*)
PROCEDURE DrawText     (textBuf: QDPtr; firstByte,byteCount: INTEGER);(*INLINE $A885*)
PROCEDURE CharWidth    (ch: CHAR): INTEGER;             (*INLINE $A88D*)
PROCEDURE StringWidth  (s:StrPtr): INTEGER;             (*INLINE $A88C*)
PROCEDURE TextWidth    (textBuf: QDPtr; firstByte,byteCount: INTEGER): INTEGER;
                                                        (*INLINE $A886*)
PROCEDURE GetFontInfo  (VAR info: FontInfo);            (*INLINE $A88B*)
PROCEDURE TextBox(inText:Ptr;textLength:LongInt;VAR r:Rect; style:INTEGER );
(*Box drawing utility*)   (*INLINE $A9CE*)

(* Point Calculations *)
PROCEDURE AddPt         (src: Point; VAR dst: Point);   (*INLINE $A87E*)
PROCEDURE SubPt         (src: Point; VAR dst: Point);   (*INLINE $A87F*)
PROCEDURE SetPt         (VAR pt: Point; h,v: INTEGER);  (*INLINE $A880*)
PROCEDURE EqualPt       (pt1,pt2: Point): BOOLEAN;      (*INLINE $A881*)
PROCEDURE ScalePt       (VAR pt: Point;VAR fromRect,toRect: Rect);(*INLINE $A8F8*)
PROCEDURE MapPt         (VAR pt: Point;VAR fromRect,toRect: Rect);(*INLINE $A8F9*)
PROCEDURE LocalToGlobal (VAR pt: Point);                (*INLINE $A870*)
PROCEDURE GlobalToLocal (VAR pt: Point);                (*INLINE $A871*)

(* Rectangle Calculations *)
PROCEDURE SetRect    (VAR r:Rect;left,top,right,bottom:INTEGER);(*INLINE $A8A7*)
PROCEDURE EqualRect  (VAR rect1,rect2: Rect): BOOLEAN;  (*INLINE $A8A6*)
PROCEDURE EmptyRect  (VAR r: Rect): BOOLEAN;            (*INLINE $A8AE*)
PROCEDURE OffsetRect (VAR r: Rect; dh,dv: INTEGER);     (*INLINE $A8A8*)
PROCEDURE MapRect    (VAR r,fromRect,toRect: Rect);     (*INLINE $A8FA*)
PROCEDURE InsetRect  (VAR r: Rect; dh,dv: INTEGER);     (*INLINE $A8A9*)
PROCEDURE SectRect   (VAR src1,src2,dstRect: Rect): BOOLEAN;(*INLINE $A8AA*)
PROCEDURE UnionRect  (VAR src1,src2,dstRect: Rect);     (*INLINE $A8AB*)
PROCEDURE PtInRect   (pt: Point;VAR r: Rect): BOOLEAN;  (*INLINE $A8AD*)
PROCEDURE Pt2Rect    (pt1,pt2: Point;VAR dstRect: Rect);(*INLINE $A8AC*)

(* Graphical Operations on Rectangles *)
PROCEDURE FrameRect  (VAR r: Rect);                     (*INLINE $A8A1*)
PROCEDURE PaintRect  (VAR r: Rect);                     (*INLINE $A8A2*)
PROCEDURE EraseRect  (VAR r: Rect);                     (*INLINE $A8A3*)
PROCEDURE InvertRect (VAR r: Rect);                     (*INLINE $A8A4*)
PROCEDURE FillRect   (VAR r: Rect;VAR pat: Pattern);    (*INLINE $A8A5*)

(* Graphical Operations on BitMaps *)
PROCEDURE ScrollRect(VAR dstRect: Rect; dh,dv: INTEGER; updateRgn: RgnHandle);
                                                        (*INLINE $A8EF*)
PROCEDURE CopyBits  (VAR srcBits,dstBits: BitMap;
                     VAR srcRect,dstRect: Rect;
                     mode:            INTEGER;
                     maskRgn:         RgnHandle);       (*INLINE $A8EC*)

(* a subset of region handling routines *)
PROCEDURE NewRgn():   RgnHandle;                        (*INLINE $A8D8*)
PROCEDURE DisposeRgn (rgn: RgnHandle);                  (*INLINE $A8D9*)
PROCEDURE CopyRgn    (srcRgn,dstRgn: RgnHandle);        (*INLINE $A8DC*)
PROCEDURE SetEmptyRgn(rgn: RgnHandle);                  (*INLINE $A8DD*)
PROCEDURE SetRectRgn (rgn: RgnHandle;
                      left,top,right,bottom:INTEGER);   (*INLINE $A8DE*)
PROCEDURE FrameRgn   (rgn: RgnHandle);                  (*INLINE $A8D2*)
PROCEDURE PaintRgn   (rgn: RgnHandle);                  (*INLINE $A8D3*)
PROCEDURE EraseRgn   (rgn: RgnHandle);                  (*INLINE $A8D4*)
PROCEDURE InvertRgn  (rgn: RgnHandle);                  (*INLINE $A8D5*)
PROCEDURE FillRgn    (rgn: RgnHandle;VAR pat: Pattern); (*INLINE $A8D6*)

(* Miscellanous Routines *)
PROCEDURE GetIcon(iconID:    INTEGER):  Handle;         (*INLINE $A9BB*)
PROCEDURE PlotIcon(VAR theRect: Rect; theIcon: Handle); (*INLINE $A94B*)
PROCEDURE GetPattern(patID: INTEGER):  PatHandle;       (*INLINE $A9B8*)

END QuickDraw.
